<template>
	<view>
		<u-navbar title="添加银行卡"  back-icon-size='48' :border-bottom='false'></u-navbar>
		<view class="main">
			<u-form :model="bankFrom" ref="uForm" label-position='top'>
				<u-form-item :border-bottom='false' label="持卡人" prop="cardholder">
					<u-input v-model="bankFrom.cardholder" placeholder='请输入持卡人姓名' />
				</u-form-item>
				<u-form-item :border-bottom='false' label="银行卡号" prop="bank_number">
					<u-input v-model="bankFrom.bank_number" type='number' placeholder='请输入银行卡号' />
				</u-form-item>
				<u-form-item :border-bottom='false' label="银行名称" prop="bank_name">
					<u-input v-model="bankFrom.bank_name" placeholder='请输入银行名称' />
				</u-form-item>
				<u-form-item :border-bottom='false' label="支行名称" prop="bank_branch">
					<u-input v-model="bankFrom.bank_branch" placeholder='请输入支行名称' />
				</u-form-item>
			</u-form>
			<view class="sunBtn" @click="submit">
				确定
			</view>
		</view>
	</view>
</template>

<script>
	import myRequest from '@/api/index.js'
	export default {
		data() {
			return {
				bankFrom: {
					cardholder: '',
					bank_number: '',
					bank_name: '',
					bank_branch: '',
				},
				rules: {
					cardholder: [{
						required: true,
						message: '请输入持卡人姓名',
						trigger: 'blur',
					}],
					bank_number: [{
						required: true,
						message: '请输入银行卡号',
						trigger: 'blur',
					}],
					bank_name: [{
						required: true,
						message: '请输入银行名称',
						trigger: 'blur',
					}],
					bank_branch: [{
						required: true,
						message: '请输入银行名称',
						trigger: 'blur',
					}]
				},
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules)
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(async valid => {
					if (valid) {
						// 验证通过
						let res = await myRequest.addBankcard({
							cardholder: this.bankFrom.cardholder,
							bank_number: this.bankFrom.bank_number,
							bank_name: this.bankFrom.bank_name,
							bank_branch: this.bankFrom.bank_branch,
						})
						if (res.status) {
							uni.showToast({
								title: res.msg
							})
							setTimeout(function() {
								uni.navigateTo({
									url: './bankCard'
								})
							}, 1000)
						}
					} else {
						console.log('验证失败');
					}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.main {
		padding: 32rpx 28rpx;

		.sunBtn {
			margin: 140rpx auto 0;
			width: 660rpx;
			height: 100rpx;
			background: linear-gradient(180deg, #FB8703 0%, #F7270C 100%);
			border-radius: 16rpx;
			text-align: center;
			font-size: 34rpx;
			font-family: Segoe UI;
			font-weight: 400;
			line-height: 100rpx;
			color: #FFFFFF;
		}
	}

	/deep/ .u-form-item {
		background-color: #FFFFFF;
		border-radius: 16rpx;
		margin-bottom: 32rpx;
		padding-left: 24rpx;
		padding-right: 24rpx;
	}
</style>
